package com.molin.API.test1;

public class Demo4StringBuilder {
    public static void main(String[] args) {
        //按照指定格式返回字符串
        //int[] arr={1,2,3}  ==> [1,2,3]这样的格式
        int[] arr={1,2,3};
        System.out.println(arrToString(arr));
    }
    public static String arrToString(int[] arr){
        StringBuilder sb=new StringBuilder("[");
        for(int i=0;i<arr.length;i++){
                sb.append(arr[i]);
                if(i==arr.length-1){
                    sb.append("]");
                }else {
                    sb.append(",");
                }
        }
        return sb.toString();
    }
}
